﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace TestGitHubBearer.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class IndexController : ControllerBase
    {
        // For example, in curl you can set the Authorization header like this:
        //     curl -H "Authorization: token GITHUB-OAUTH-TOKEN" http://localhost:5000/index

        [HttpGet]
        [Authorize]
        public ActionResult Get()
        {
            var claims = User.Identities.First(i => i.AuthenticationType == "GitHubBearer").Claims;
            return Ok(claims.Select(c => new { c.Type, c.Value }));
        }
    }
}
